home *** CD-ROM | disk | FTP | other *** search
Wrap
// GETINFO SCRIPTING // Culturalia (Con Portada) (*************************************************** * Movie importation script for: * * Culturalia, http://www.culturalianet.com * * * * Original version made by David Arenillas * * New version made by Antoine Potten * * Contributors: * * Jose Miguel Folgueira * * RedDwarf * * Hades666 * * KaBeCi * * PolloPolea * * * * Sort Results Made by Moises DΘniz 13/04/2004 * * * * TransformTitle function from IMDB (US) Script * * (c) 2002-2004 Antoine Potten * * software@antp.be * * Contributors : * * Danny Falkov * * Kai Blankenhorn * * lboregard * * Ork <ork@everydayangels.net> * * Trekkie <Asimov@hotmail.com> * * * * Thanks to Culturalia's webmaster for his help * * and for providing more direct access to his * * database * * * * For use with Ant Movie Catalog 3.4.x * * www.antp.be/software/moviecatalog * * * * This program is free software; you can * * redistribute it and/or modify it under the * * terms of the GNU General Public License as * * published by the Free Software Foundation; * * either version 2 of the License, or (at your * * option) any later version. * ***************************************************) program Culturalia; const BaseURL = 'http://www.culturalianet.com/bus/catalogo.php'; TitleMixedCase = False; // If true, each letter of each word of title begins with Uppercase. If false, the script transforms the titles in lowercase except first word ExternalPictures = False; { True: Pictures will be stored as external files in the folder of the catalog False: Pictures will be stored inside the catalog (only for .amc files) } // Donde vamos a buscar en el caso de no haber introducido ni el tφtulo original ni el traducido en los campos correspondientes, sino en la ventana que // se abre y nos lo solicita. // 1-Titulo traducido, 2-Titulo original, 3-General // What type of search in case we don't write the original title nor traslated one in the corresponding fields, we do it in the input box. // 1-Translated title, 2-Original Title, 3-General defdonde='1'; var MovieName: string; tmp: string; donde: string; Articles: array of string; Index: Integer; function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer; var i: Integer; begin result := -1; if StartAt < 0 then StartAt := 0; for i := StartAt to List.Count-1 do if Pos(Pattern, List.GetString(i)) <> 0 then begin result := i; Break; end; end; function TransformTitle(Title: string): string; var BeginPos, EndPos: Integer; Value: string; Words: array of string; Articles: array of string; Replace,Original: string; Index, CommaCount: Integer; Begin // Original Title Result:=Title; Setarraylength(Words,11); Words[0]:=' In '; Words[1]:=' On '; Words[2]:=' Of '; Words[3]:=' As '; Words[4]:=' The '; Words[5]:=' At '; Words[6]:=' And A '; Words[7]:=' And '; Words[8]:=' An '; Words[9]:=' To '; Words[10]:=' For '; SetArrayLength(Articles,35); Articles[0]:=' The'; Articles[1]:=' a'; Articles[2]:=' An'; Articles[3]:=' Le'; Articles[4]:=' L'''; Articles[5]:=' Les'; Articles[6]:=' Der'; Articles[7]:=' Das'; Articles[8]:=' Die'; Articles[9]:=' Des'; Articles[10]:=' Dem'; Articles[11]:=' Den'; Articles[12]:=' Ein'; Articles[13]:=' Eine'; Articles[14]:=' Einen'; Articles[15]:=' Einer'; Articles[16]:=' Eines'; Articles[17]:=' Einem'; Articles[18]:=' Il'; Articles[19]:=' Lo'; Articles[20]:=' La'; Articles[21]:=' I'; Articles[22]:=' Gli'; Articles[23]:=' Le'; Articles[24]:=' Uno'; Articles[25]:=' Una'; Articles[26]:=' Un'''; Articles[27]:=' O'; Articles[28]:=' Os'; Articles[29]:=' As'; Articles[30]:=' El'; Articles[31]:=' Los'; Articles[32]:=' Las'; Articles[33]:=' Unos'; Articles[34]:=' Unas'; // Count the Comma in The Title CommaCount := 0; EndPos := 0; Value := Title; repeat BeginPos := Pos(',', Value); if BeginPos > 0 then begin Delete(Value, 1, BeginPos); CommaCount := CommaCount + 1; EndPos := EndPos + BeginPos; end; until( Pos(',',Value) = 0); // Compare the Article to a list of known ones for Index := 0 to 34 do begin if Pos(Articles[Index], Value) <> 0 then begin CommaCount := 1; BeginPos := EndPos; Break; end; end; if (BeginPos > 0) and (CommaCount = 1) then begin Value := Copy(Title, BeginPos + 1, Length(Title)); Value := Trim(Value); Result := Value + ' ' + Copy(Title, 1, BeginPos - 1); end; BeginPos := Pos(': ', Result); if BeginPos > 0 then Result := StringReplace(Result, ': ', ' - '); If TitleMixedCase then Result := AnsiMixedCase(Result, ' ') else begin Result := AnsiLowerCase(Result); Result := AnsiUpFirstLetter(Result); end; for Index := 0 to 10 do begin if Pos(Words[Index],Result) <> 0 then begin Original := Words[Index]; Replace := AnsiLowerCase(Original); Result := StringReplace(Result, Original, Replace); end; end; Result := StringReplace(Result, ' - the ', ' - The '); Result := Trim(Result); end; function Valoracion(Resultado: string; Titulo :TStringList) : Integer; var i,j,val: integer; begin val := 0; for i := 0 to Titulo.Count-1 do begin if (Pos(Titulo.GetString(i),Resultado) > 0) then val := val + 5; end; Valoracion := val; end; procedure SortStrings(var List : TStringList; Nombre : string); var i,j,ValI,ValJ: integer; NombreArray: TStringList; palabra : string; begin Nombre := LowerCase(Nombre); NombreArray := TStringList.Create; while ((pos(' ',Nombre) > 0) and (Length(Nombre)> 0)) do begin palabra := copy(Nombre,0,pos(' ',Nombre)-1); Nombre := copy(Nombre,pos(' ',Nombre)+1,Length(Nombre)); NombreArray.Add(palabra); end NombreArray.Add(Nombre); for i := 0 to List.Count-1 do begin for j := 0 to List.Count-1 do begin ValI := Valoracion(LowerCase(List.GetString(i)),NombreArray); ValJ := Valoracion(LowerCase(List.GetString(j)),NombreArray); if (ValI > ValJ) then begin List.Exchange(i,j); end; if (ValI = ValJ) and (List.GetString(i) < List.GetString(j)) then List.Exchange(i,j); end; end; NombreArray.Free; end; procedure AnalyzePage(Address,Nombre: string); var Page,TempTit: TStringList; LineNr,i: Integer; Code, Title, TitleOrig, Year,Texto,Url: string; begin Page := TStringList.Create; TempTit := TStringList.Create; Page.Text := GetPage(Address); if Pos('No se ha encontrado ning·n artφculo por tφtulo', Page.Text) > 0 then begin ShowMessage('No se ha encontrado ninguna coincidencia por tφtulo'); end else begin PickTreeClear; LineNr := 1; Page.Text := StringReplace(Page.Text, '<br>', #13#10); while LineNr + 3 < Page.Count do begin Code := GetValueAfter(Page.GetString(LineNr), 'Codigo = '); Title := GetValueAfter(Page.GetString(LineNr+1), 'Titulo = '); TitleOrig := GetValueAfter(Page.GetString(LineNr+2), 'Titulo original = '); Year := GetValueAfter(Page.GetString(LineNr+3), 'A±o = '); TempTit.Add(Title + ' (' + TitleOrig + '), ' + Year+';'+BaseURL + '?catalogo=1&codigo=' + Code); LineNr := LineNr + 5; end; SortStrings(TempTit,Nombre); PickTreeAdd('Resultados mßs probables de buscar: "'+Nombre+'"', ''); for i := 0 to TempTit.Count-1 do begin Texto := copy(TempTit.GetString(i),0,Pos(';',TempTit.GetString(i))-1); Url := copy(TempTit.GetString(i),Pos(';',TempTit.GetString(i)),Length(TempTit.GetString(i))); PickTreeAdd(Texto,Url); if (i = 0) then PickTreeAdd('Resto de resultados de buscar: "'+Nombre+'"', ''); end; Page.Free; TempTit.Free; if PickTreeExec(Address) then AnalyzeMoviePage(Address); end; end; procedure AnalyzeMoviePage(Address: string); var Page: TStringList; Comments: string; strTitle: string; strSinopsis: string; Line: string; LineNr: Integer; tmp: string; begin Page := TStringList.Create; Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10); Page.Text := StringReplace(Page.Text, '<br>', #13#10); strTitle := GetValueAfter(Page.GetString(1), 'Titulo = '); if copy(strTitle, Length(strTitle), Length(strTitle)) = '.' then begin tmp := Copy(strTitle, 1, Length(strTitle) -1); end else begin tmp := strTitle; end; SetField(fieldTranslatedTitle, TransformTitle(tmp)); tmp := GetValueAfter(Page.GetString(2), 'Titulo original = '); SetField(fieldOriginalTitle, TransformTitle(tmp)); SetField(fieldYear, GetValueAfter(Page.GetString(3), 'A±o = ')); SetField(fieldCategory, GetValueAfter(Page.GetString(4), 'Genero = ')); SetField(fieldCountry, GetValueAfter(Page.GetString(5), 'Nacion = ')); SetField(fieldDirector, GetValueAfter(Page.GetString(6), 'Director = ')); SetField(fieldActors, GetValueAfter(Page.GetString(7), 'Actores = ')); SetField(fieldProducer, GetValueAfter(Page.GetString(8), 'Productor = ')); Comments := 'Gui≤n: ' + GetValueAfter(Page.GetString(9), 'Guion = '); Comments := Comments + #13#10 + 'Fotografφa: ' + GetValueAfter(Page.GetString(10), 'Fotografia = '); Comments := Comments + #13#10 + 'M·sica: ' + GetValueAfter(Page.GetString(11), 'Musica = '); SetField(fieldComments, Comments); LineNr := FindLine('Sinopsis = ', Page, 0); Line := Page.GetString(LineNr); strSinopsis := GetValueAfter(Line, 'Sinopsis = '); LineNr := LineNr + 1; Line := Page.GetString(LineNr); while pos('URL = ', Line) = 0 do begin strSinopsis := strSinopsis + #13#10 + Line; LineNr := LineNr + 1; Line := Page.GetString(LineNr); end HTMLRemoveTags(strSinopsis); SetField(fieldDescription, StringReplace(StringReplace(strSinopsis, 'ô', '"'), 'ö', '"')); LineNr := FindLine('URL = ', Page, 0); if LineNr <> -1 then SetField(fieldURL, GetValueAfter(Page.GetString(LineNr), 'URL = ')); LineNr := FindLine('Imagen = ', Page, 0); if LineNr <> -1 then GetPicture(GetValueAfter(Page.GetString(LineNr), 'Imagen = '), ExternalPictures); Page.Free; DisplayResults; end; function GetValueAfter(Line, Identifier: string): string; begin if Pos(Identifier, Line) = 1 then Result := Copy(Line, Length(Identifier)+1, Length(Line)) else Result := ''; end; begin SetArrayLength(Articles,11); Articles[0]:='Lo '; Articles[1]:='La '; Articles[2]:='Le '; Articles[3]:='Uno '; Articles[4]:='Una '; Articles[5]:='Un '; Articles[6]:='El '; Articles[7]:='Los '; Articles[8]:='Las '; Articles[9]:='Unos '; Articles[10]:='Unas '; if CheckVersion(3,4,0) then begin MovieName := GetField(fieldOriginalTitle); donde := '&donde=2'; if MovieName = '' then begin MovieName := GetField (fieldTranslatedTitle); donde := '&donde=1'; end if MovieName = '' then begin Input('Importar de Culturalia', 'Introduce el Titulo de la Pelicula:', MovieName); donde := '&donde=' + defdonde; end if MovieName <> '' then begin // Eliminate spanish article if exists for Index := 0 to 10 do begin if Pos(Articles[Index], MovieName) <> 0 then MovieName := copy(MovieName, length(Articles[Index]), length(MovieName)); end; // Eliminate point(s) at final of MovieName before search tmp := MovieName; if Copy(tmp, Length(tmp), Length(tmp)) = '.' then MovieName := Copy(tmp, 1, Length(tmp) -1); AnalyzePage(BaseURL + '?catalogo=1&texto=' + UrlEncode(MovieName) + donde, MovieName); end; end else ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)'); end.